package auto.crud.util;

import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by watso on 2018/2/14.
 */
public class AutoInit {

    public static Map<String, Object> initAddColumnValue(Map<String, Object> entityMap){
        if (entityMap==null) return null;
        Map<String, Object> autoMap = new HashMap<>();
        Set<String> columnSet = entityMap.keySet();
        String addColumn = StringUtils.join(columnSet,",");

        StringBuffer addValues = new StringBuffer();

        for (String key : columnSet){
            addValues.append("'");
            addValues.append(entityMap.get(key));
            addValues.append("',");
        }

        autoMap.put("addColumn",addColumn);
        autoMap.put("addValue",addValues.substring(0,addValues.length()-1));
        return autoMap;
    }

}
